<#import "../tpl/pageTep.ftl" as page>
<@page.pageBase currentMenu="机构管理">
<style>
    .form-horizontal .controls {
        line-height: 40px;
        height: 40px;
    }
    .button-primary {
           margin-left: 5px;
       }
</style>
<form id="searchForm" class="form-panel"  action="${basepath}/manage/organize/loadData">
    <ul class="panel-content">
        <li>
            <div class="control-group span5">
                <div class="search-controls  controls">
                    <input type="text" name="name" id="title" value="" placeholder="搜索机构名称、负责人">
                </div>
            </div>
            <div class="form-actions span2">
                <button type="submit" class="button  button-primary">
                    搜索
                </button>
            </div>
        </li>
    </ul>
</form>

<div id="grid"></div>
<script>
    /*--------------------------------------------------------表格数据渲染 start-----------------------------------*/
    var Grid = BUI.Grid,
            Store = BUI.Data.Store,
            columns = [
                {title: '机构名称', dataIndex: 'name', width: "12.5%", elCls: 'center'},
                {
                    title: '机构级别', dataIndex: 'rank', width: "12.5%", elCls: 'center', renderer: function (data) {
                    if (data == "1") {
                        return 'A级';
                    }
                    if (data == "2") {
                        return 'B级';
                    } if(data =="3") {
                        return 'C级';
                    }else{
                        return '无';
                    }
                }
                },
                {
                    title: '所在地区', dataIndex: 'province', width: "12.5%", elCls: 'center', renderer: function (value, data) {
                    return data.province + data.city + data.area + data.address;
                }
                },

                {title: '负责人', dataIndex: 'principal', width: "12.5%", elCls: 'center'},
                {title: '联系电话', dataIndex: 'principalPhone', width: "12.5%", elCls: 'center'},
                {
                    title: '志愿者数量', dataIndex: 'accountNum', width: "12.5%", elCls: 'center', renderer: function (data, obj) {
                    return '<a href="${basepath}/manage/organize/toAccountList?id=' + obj.id + '">' + data + '</a>';
                }
                },
                {
                    title: '活动数量', dataIndex: 'offlineNum', width: "12.5%", elCls: 'center', renderer: function (data, obj) {//获取机构ID
                    return '<a href="${basepath}/manage/organize/toOfflineList?id=' + obj.id + '">' + data + '</a>';
                }
                },
                {
                    title: '操作', width: "12.5%", elCls: 'center', dataIndex: 'id', renderer: function (value) {
                    return '<a   href="${basepath}/manage/organize/toEdit?id=' + value + '">查看</a> ';
                }
                }
            ];
    var store = new Store({
                url: 'loadData',
                autoLoad: true, //自动加载数据
                params: { //配置初始请求的参数
                    length: '10',
                    status: '1'
                },
                pageSize: 10,	// 配置分页数目
                root: 'list',
                totalProperty: 'total'
            }),
            grid = new Grid.Grid({
                render: '#grid',
                columns: columns,
                loadMask: true, //加载数据时显示屏蔽层
                store: store,
                plugins: [Grid.Plugins.CheckSelection], // 插件形式引入多选表格

                // 底部工具栏
                bbar: {
                    pagingBar: true
                }
            });
    grid.render();

    var form = new BUI.Form.HForm({
        srcNode: '#searchForm'
    }).render();

    form.on('beforesubmit', function (ev) {
        ///序列化成对象
        var obj = form.serializeToObject();
        obj.start = 0; //返回第一页
        store.load(obj);
        return false;
    });
    /*---------------------------------------------------表格数据渲染 end-------------------------------------------*/
    /*----------------------------------------------编辑冻结状态 begin------------------------------------*/
    //编辑表单处理̬
    var editForm = new BUI.Form.Form({
        srcNode: '#editForm',
        submitType: 'ajax',
        callback: function (data) {
            var obj = new Object();
            obj.start = 0; //返回第一页
            store.load(obj);
            editDialog.close();
        }
    });
    editForm.render();
    var editDialog = new BUI.Overlay.Dialog({
        title: '编辑等级',
        width: 500,
        height: 280,
        contentId: 'editContent',
        success: function () {
            editForm.ajaxSubmit();
        }
    });
    //编辑按钮事件
    function edit(id) {
        $.ajax({
            type: "POST",
            dataType: "json",
            url: "${basepath}/manage/organize/toEditJson",
            data: {id: id},
            success: function (data) {
                var form = $("#editForm")[0];
                BUI.FormHelper.setFields(form, data.data);
                editDialog.show();
            }
        });
    }
    /*----------------------------------------------编辑冻结状态 end------------------------------------*/
</script>

</@page.pageBase>